package com.example.uit_management;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import com.example.uit_management.R.id;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint.Join;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class Activity_list_pattern_IDStudent extends Activity {
	private Context context;
	private JsonParser_pattern_IDStudent jsonparser_pattern_IDStudent=new JsonParser_pattern_IDStudent();
	private ListView list;	
	private ArrayAdapter_PatternIDStudent adapter;
	private ArrayList<HashMap<String, String>> array_jsonparser_pattern_IDStudent=new ArrayList<HashMap<String, String>>();
	//private HashMap<String, String> jsonparser_pattern=new HashMap<String, String>();
	//private ArrayList<HashMap<String, String>> array_MAP=new ArrayList<HashMap<String, String>>();
		
	    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_pattern_idstudent);
        Menu_GridView.dialog.dismiss();
        Log.e(Activity_list_pattern_IDStudent.class.toString(), "Vao pattern ");
        
        try{
        	context = this;
        	array_jsonparser_pattern_IDStudent = jsonparser_pattern_IDStudent.getMap();
        	list=(ListView)findViewById(R.id.list_pattern_ID);	
        	// tim dia chi cho lop va khoa textview
        	TextView Khoa = (TextView)findViewById(R.id.TextView_patternID_Khoa);
        	TextView Lop = (TextView)findViewById(R.id.TextView_patternID_Lop);
        	Khoa.setText("Không tìm thấy");
        	Lop.setText("Không tìm thấy");
        	if (array_jsonparser_pattern_IDStudent.size()!=0) {
        		Khoa.setText("Khoa :"+array_jsonparser_pattern_IDStudent.get(0).get(JsonParser_pattern_IDStudent.KEY_facultyID));
        		Lop.setText("Lớp :"+array_jsonparser_pattern_IDStudent.get(0).get(JsonParser_pattern_IDStudent.KEY_classID));
    		}   
        	// Set gia tri cho list view
			Collections.sort(array_jsonparser_pattern_IDStudent, new ArrayMap_pattern());
			Log.e(Activity_list_pattern_IDStudent.class.toString(), "============================");
			for (int i = 0; i < array_jsonparser_pattern_IDStudent.size(); i++) {
				Log.e(Activity_list_pattern.class.toString(),"Lop "+array_jsonparser_pattern_IDStudent.get(i).get(JsonParser_pattern.KEY_classID)+ "Hoc ky " + array_jsonparser_pattern_IDStudent.get(i).get(JsonParser_pattern.KEY_patternSemester));
		}
		adapter =new ArrayAdapter_PatternIDStudent(this, array_jsonparser_pattern_IDStudent);
        // add adapter into list
        if(array_jsonparser_pattern_IDStudent.size()==0){
        	Toast.makeText(this, "Không có môn nào", Toast.LENGTH_LONG).show();
        }
        list.setAdapter(adapter);     
        }catch(Exception e){
        	e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity__score, menu);
        return true;
    }  
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menu_back:{
        	finish();  
        	Intent intent = new Intent(getApplicationContext(),Menu_GridView.class);
				startActivity(intent);				
				break;
        	}
        }
        return true;
    }     
    
}

